package com.bthdung.studios.lesson12.framework;

import android.opengl.GLES20;

public class VertexPositionTextureNormal
{
	public Vector3 Position;
	public Vector3 Normal;
	public Vector2 TextureCoordinate;

	public static int ELEMENTS_COUNT = 3 + 3 + 2;
	public static int SIZE_IN_BYTES = 4 * ELEMENTS_COUNT;

	public static final int POSITION_SIZE = 3 * 4;
	public static final int NORMAL_SIZE = 3 * 4;
	public static final int TEXTURE_COORD_SIZE = 2 * 4;

	public VertexPositionTextureNormal(Vector3 position, Vector3 normal, Vector2 textureCoordinate)
	{
		Position = position;
		Normal = normal;
		TextureCoordinate = textureCoordinate;
	}

	public VertexPositionTextureNormal()
	{
		this(Vector3.Zero, Vector3.Up, Vector2.Zero);
	}

	public static void glBindBuffersToAttribs(int position, int normal, int texcoord)
	{
		GLES20.glVertexAttribPointer(position, 3, GLES20.GL_FLOAT, false, SIZE_IN_BYTES, 0);
		GLES20.glVertexAttribPointer(normal, 3, GLES20.GL_FLOAT, false, SIZE_IN_BYTES, POSITION_SIZE);
		GLES20.glVertexAttribPointer(texcoord, 2, GLES20.GL_FLOAT, false, SIZE_IN_BYTES, POSITION_SIZE + NORMAL_SIZE);
	}

	public void copyElements(float[] target, int start)
	{
		target[start++] = Position.x;
		target[start++] = Position.y;
		target[start++] = Position.z;

		target[start++] = Normal.x;
		target[start++] = Normal.y;
		target[start++] = Normal.z;

		target[start++] = TextureCoordinate.x;
		target[start++] = TextureCoordinate.y;
	}
}
